function pageBanner(pageNum, pageSize) {
    var getData;
    $.ajax({
        url: '/banner/list',
        dataType: 'json',
        type: 'get',
        async: false,
        data: {
            pageNum: pageNum,
            pageSize: pageSize
        },
        success: function (res) {
            getData = res;
        }
    });
    return getData;
}

function idGetBanner(id) {
    var getData;
    $.ajax({
        url: '/banner/admin/' + id,
        type: 'get',
        dataType: 'json',
        async: false,
        success: function (res) {
            if (res.code != 200) {
                alert('查询失败!');
                return;
            }
            getData = res;
        }

    })
    return getData;
}

function deleteBanner(id) {
    var deleteData = '[' + id + ']';
    $.ajax({
        url: '/banner/admin/delete',
        type: 'post',
        dataType: 'json',
        contentType: 'application/json;charset=utf-8',
        data: deleteData,
        success: function (res) {
            if (res.code != 200) {
                alert(res.message);
                return;
            }
            alert("删除成功");
            show();
        }
    })
}


function idGetBannerAll(id) {
    var getData;
    $.ajax({
        url: '/banner/admin/all/' + id,
        type: 'get',
        dataType: 'json',
        async: false,
        success: function (res) {
            if (res.code != 200) {
                alert('查询失败!');
                return;
            }
            getData = res;
        }

    })
    return getData;
}

function addBanner(){
    let img = $('#img').attr("src");
    if (img == null || img == undefined) {
        img = '';
    }
    let banner = {
        "img": img,
        "description": $('#bannerDescription').val(),
        "url": $('#bannerUrl').val()
    }
    $.ajax({
        url: '/banner/admin/insert',
        type: 'post',
        contentType: 'application/json;charset=utf-8',
        data: JSON.stringify(banner),
        success: function (res){
            if(res.code != 200){
                alert("添加失败");
                return;
            }
            $("#modalClose").click();
            alert("添加成功");
            show();
        }
    })
}

function updateBanner(){
    let img = $('#img').attr("src");
    if (img == null || img == undefined) {
        img = '';
    }
    let banner = {
        "id": $('#bannerId').val(),
        "img": img,
        "description": $('#bannerDescription').val(),
        "url": $('#bannerUrl').val()
    }
    $.ajax({
        url: '/banner/admin/update',
        type: 'post',
        contentType: 'application/json;charset=utf-8',
        data: JSON.stringify(banner),
        success: function (res){
            if(res.code != 200){
                alert("修改失败");
                return;
            }
            $("#modalClose").click();
            alert("修改成功");
            show();
        }
    })
}

function setState(id){
    $.ajax({
        url: '/banner/state',
        type: 'get',
        data: {
            id: id
        },
        success: function (res) {
            console.log(res);
            if(res.code != 200){
                alert('修改失败');
                return;
            }
        }
    })
}

